#   Copyright 2006 Jerome Lacoste (jerome@coffeebreaks.org)
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
class Tracker < ActiveRecord::Base
#  attr_reader :name, :url, :id_matcher
#  attr_accessible :name, :url, :id_matcher

  validates_presence_of :name, :url

  validates_format_of :url,
                      :with => %r{^http(s|):.+$}i,
                      :message => "must be a URL."

  def as_issue_tracker
    IssueTracker::Tracker.get(self.name, self.url, self.id_matcher) unless self.name.nil?
  end

  protected 
  def validate
    begin
      Regexp.new(self.id_matcher)
    rescue RegexpError
      errors.add(:id_matcher, "should be a regular expression") unless self.id_matcher.nil?
    end
  end
 
end
